package com.bac.rentmap.ad.flat;

import java.util.ArrayList;
import java.util.List;

public enum LocalAddressPrefix {
    street("ул.", new String[] { "ул", "улица", "улице" }), avenue("просп.",
            new String[] { "проспект", "пр-т", "просп" }), lane("пер.",
            new String[] { "пер" }), square("пл.", new String[] { "пл",
            "площадь" });
    private String name;
    private String[] synonyms;

    private LocalAddressPrefix(String name, String[] synonyms) {
        this.name = name;
        this.synonyms = synonyms;
    }

    public String getName() {
        return name;
    }

    public static LocalAddressPrefix valueOfName(String value) {
        for (LocalAddressPrefix localAddressPrefix : LocalAddressPrefix
                .values()) {
            if (localAddressPrefix.name.equals(value))
                return localAddressPrefix;
        }
        throw new IllegalArgumentException("Can't find prefix for " + value);
    }

    public static LocalAddressPrefix valueOfSynonym(String value) {
        for (LocalAddressPrefix localAddressPrefix : LocalAddressPrefix
                .values()) {
            for (String synonym : localAddressPrefix.synonyms) {
                if (value.toLowerCase().matches(synonym)) {
                    return localAddressPrefix;
                }
            }
        }
        throw new IllegalArgumentException("Can't find prefix for " + value);
    }

    public static List<String> getSynonymPatterns() {
        List<String> res = new ArrayList<String>();
        for (LocalAddressPrefix localAddressPrefix : LocalAddressPrefix
                .values()) {
            for (String synonym : localAddressPrefix.synonyms) {
                res.add(synonym);
            }
        }
        return res;
    }
}
